//
//  SidebarViewController.m
//  LLBlurSidebar
//
//  Created by Lugede on 14/11/20.
//  Copyright (c) 2014年 lugede.cn. All rights reserved.
//

#import "SidebarViewController.h"
#import "RootViewController.h"

@interface SidebarViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, retain) UITableView* menuTableView;

@end

@implementation SidebarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    // 列表
    self.menuTableView = [[UITableView alloc] initWithFrame:self.contentView.bounds];
    //不显示分隔线
    [self.menuTableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    self.menuTableView.backgroundColor = [UIColor clearColor];
    self.menuTableView.delegate = self;
    self.menuTableView.dataSource = self;
    
    [self.view addSubview:self.menuTableView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//设置行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 6;
}

//设置cell高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        return 80;
    }
    return 50;
}
//设置cell上的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //缓冲池
    static NSString *sidebarMenuCellIdentifier = @"CellIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:sidebarMenuCellIdentifier];
    //判断是否为空
    if(!cell) {
        //创建新的cell
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sidebarMenuCellIdentifier] ;
        cell.backgroundColor = [UIColor clearColor];
        
    }
    //将cell设置成点击时不变色
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    cell.textLabel.textColor = [UIColor whiteColor];

    if (indexPath.row == 0) {
        //创建左侧抽屉上的头像
        UIImageView *headPhotoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 60, 60)];
        headPhotoImageView.backgroundColor = [UIColor yellowColor];
        headPhotoImageView.layer.masksToBounds = YES;
        headPhotoImageView.layer.cornerRadius = 30;
        headPhotoImageView.layer.borderWidth = 2;
        headPhotoImageView.layer.borderColor = [UIColor grayColor].CGColor;
        [self.view addSubview:headPhotoImageView];
    }
    if (indexPath.row == 1) {
        cell.textLabel.text = @" 登陆";
    }
    if (indexPath.row == 2) {
        cell.textLabel.text = @"账户信息";
    }
    if (indexPath.row == 3) {
        cell.textLabel.text = @"清除缓存";
    }
    if (indexPath.row == 4) {
        cell.textLabel.text = @"版本信息";
    }
    if (indexPath.row == 5) {
        cell.textLabel.text = @"关于我们";
    }

    return cell;
}
//点击cell触发的方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//    [tableView deselectRowAtIndexPath:indexPath animated:YES];
//    
//    RootViewController *controller = nil;
//    id next = [self nextResponder];
//    while(![next isKindOfClass:[RootViewController class]])//这里跳不出来。。。
//    {
//        next = [next nextResponder];
//    }
//    if ([next isKindOfClass:[RootViewController class]])
//    {
//        controller = (RootViewController *)next;
//    }
    
//    switch (indexPath.row) {
//        case 0:
//            controller.bgImageView.image = [UIImage imageNamed:@"img0"];
//            break;
//        case 1:
//            controller.bgImageView.image = [UIImage imageNamed:@"img1"];
//            break;
//        case 2:
//            controller.bgImageView.image = [UIImage imageNamed:@"img2"];
//            break;
//        default:
//            break;
//    }
    //隐藏侧拉门
    [self showHideSidebar];
    if (indexPath.row == 1) {
        
        [self.loginDalegate changeLogin];
    }

    
}

@end
